package com.ssm.mssm.web.handler;

//import com.ssm.common.ThisSystemException;
import com.ssm.mssm.entity.InformationEntity;
import com.ssm.mssm.function.InformationFunction;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
//import org.springframework.web.bind.annotation.RequestMethod;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * Created by asus on 2017/7/13.
 */
@Controller
public class LoginHandler {

    @Autowired
    InformationFunction ifun;

    @RequestMapping("/login.do")
    public String login(String account, String password, HttpServletRequest request){
        try{
            System.out.println("account"+account);
            InformationEntity i=ifun.login(account,password);
            HttpSession session=request.getSession();
            session.setAttribute("currentUser",i);
        }catch(Exception e){
            request.setAttribute("message",e.getMessage());
            return "forward:/login.jsp";
        }
        return "redirect:/index.do";
    }

    @RequestMapping("/index.do")
    public String index(){
        return "index";
    }

    @RequestMapping("/welcome.do")
    public String welcome(){
        return "welcome";
    }

    @RequestMapping("/logout.do")
    public String logout(HttpSession session){
        session.invalidate();
        return "redirect:/login.jsp";
    }

}
